<#include "/WEB-INF/views/admin/common/layout/__formlayout.html">
<#assign pageCss>
<link rel="stylesheet" href="${ctx}/resource/validationengine/css/validationEngine.jquery.css">
</#assign>
<#assign pageScript>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	<#if user??>
		$("#type").val(${user.type});
		$("#des").text("${user.des}");
		$("#name").attr("disabled",true)
	</#if>
		
	
	
	$("#frm").validationEngine('attach', {
		promptPosition : 'topLeft',
		scroll : false
	});
	
	$("#role").change(function() {
		var selected = $("#role option:selected").text();
		if(selected == "Customer"){
			$("div[name='trigger']").each(function(){
				$(this).show();
			});
		}else{
			$("div[name='trigger']").each(function(){
				$(this).hide();
			});
		}
		
	});
	
	$("#subBtn").click(function() {
		var frm = $("#frm");
		if (frm.validationEngine("validate")) {
			$.ajax({
				type : "POST",
				url : "${ctx}/admin/sys/offer/save_update",
				data : frm.serialize(),
				success : function(result) {
					if (result.isSuccess) {
						layer.msg(result.msg, {
							icon : 1,
							time : 1000,
							end : function() {
								//信息提示完成后关闭表单窗口
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭  
							}
						});
					} else {
						layer.msg(result.msg, {
							time : 1000,
							icon : 2
						});
					}
				}
			});
		}
	});
});
</script>
</#assign>
<@formlayout>
<div class="row">
	<div class="am-u-sm-12 am-u-md-12 am-u-lg-12" style="width:800px;height:600px">
		<div class="widget am-cf">
			<div class="widget-body am-fr">
				<form class="am-form tpl-form-border-form" id="frm"
					action="${ctx}/admin/sys/offer/save">
					<input type="hidden" 
								class="tpl-form-input validate[required]" id="owner" value="${offer.owner!}" 
								name="offer.owner">
					<#if offer??>
					<div class="am-form-group">
						<label for="click_url" class="am-u-sm-3 am-form-label">click_url </label>
						<div class="am-u-sm-9">
							<input type="text" disabled="disabled"
								class="tpl-form-input validate[required,costom[url]]" id="click_url" value="${offer.click_url!}" 
								name="offer.click_url" placeholder="please enter click_url">
						</div>
					</div>
					<#else>
					<div class="am-form-group">
						<label for="click_url" class="am-u-sm-3 am-form-label">click_url </label>
						<div class="am-u-sm-9">
							<input type="text"
								class="tpl-form-input validate[required,costom[url]]" id="click_url" value="${offer.click_url!}" 
								name="offer.click_url" placeholder="please enter click_url">
						</div>
					</div>
					</#if>
					<div class="am-form-group">
						<label for="click_url" class="am-u-sm-3 am-form-label">price </label>
						<div class="am-u-sm-9">
							<input type="text"
								class="tpl-form-input validate[required,custom[price]]" id="price" value="${offer.price!}" 
								name="offer.price" placeholder="please enter price">
						</div>
					</div>
					<div class="am-form-group">
						<div class="am-u-sm-9 am-u-sm-push-3">
							<button type="button"
								class="am-btn am-btn-primary tpl-btn-bg-color-success "
								id="subBtn">submit</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
</@formlayout>

